package com.hs.panghu.dao.imp;

import com.hs.panghu.dao.AdminDao;
import com.hs.panghu.entity.Admin;
import com.hs.panghu.util.JDBCDruidUtil;

import java.sql.ResultSet;
import java.sql.SQLException;

public class AdminDaoImpl implements AdminDao {
    @Override
    public Admin selectAdminByUsernameAndPassword(String username, String password) {
        Admin admin = null;
        String sql = "select * from admin where username = ? and password = ?";
        Object object[] = {username,password};
        ResultSet resultSet = JDBCDruidUtil.query(sql, object);
        try {
            if(resultSet.next()){
                admin = new Admin(
                        resultSet.getInt(1),
                        resultSet.getString(2),
                        resultSet.getString(3)
                );
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
           JDBCDruidUtil.close();
        }
        return admin;
    }
}
